package com.yswwpp.cross;

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

/**
 * 
 * @author siwen
 *
 */
public interface IProtocol
{

	// ----------------------------------------------------
	// Mina数据长度定义
	// ----------------------------------------------------

	/**
	 * byte 1个字节 short 2个字节 char 2个字节 int 4个字节 long 8个字节 float 4个字节 double 8个字节
	 */

	// ----------------------------------------------------
	//
	// ----------------------------------------------------


	public final static String CHARTSET_NAME_UTF_8 = "UTF-8";
	
	public static final CharsetEncoder ENCODER_CHARSET=Charset.forName("UTF-8").newEncoder();
	   
	   public static final CharsetDecoder DECODER_CHARSET=Charset.forName("UTF-8").newDecoder();

	// ----------------------------------------------------
	// 协议
	// ----------------------------------------------------

	// 通过基址计算协议类型右移的位数
	public final static short PROTOCOL_TAG_OFFSET_LEN = 12;

	// 协议标签基址
	public final static short PROTOCOL_TAG_KERNEL = 0x1000; // 0001 0000 0000
															// 0000 //内核段
	public final static short PROTOCOL_TAG_SYSTEM = 0x2000; // 0010 0000 0000
															// 0000 //系统段
	public final static short PROTOCOL_TAG_APPONE = 0x3000; // 0011 0000 0000
															// 0000 //应用1段
	public final static short PROTOCOL_TAG_APPTWO = 0x4000; // 0100 0000 0000
															// 0000 //应用2段

	public final static short PROTOCOL_TAG_DEFAULT = 0x0000; // 默认tag

	// 消息缓存最大数量
	public final static int MESSAGE_POOL_SIZE = 50000;

	/**
	 * 消息返回正常
	 */
	public final static int MESSAGE_RET_OK = 0;
	/**
	 * 查询记录不存在
	 */
	public final static int MESSAGE_RET_ERROR_NOT_FOUND = 202004;

	// ----------------------------------------------------
	// 协议
	// ----------------------------------------------------

	// 协议标识
	public final static byte PROTOCOL_SEG = 'y';

	// 协议版本
	public final static byte PROTOCOL_VER_01 = 0x01;
	
	public final static byte PROTOCOL_VER_DEFAULT = PROTOCOL_VER_01;

	// 序列号固定长度
	public final static int PROTOCOL_SEQ_LEN = 32; //

	// ----------------------------------------------------
	/**
	 * 来源于司机宝
	 */
	public final static int FROM_SIJIBAO = 1;
	/**
	 * 来源于爬虫
	 */
	public final static int FROM_SPIDER = 2;

	// ----------------------------------------------------
	//
	// ----------------------------------------------------

	public final static int BASE_lEN = 1 + 1 + 2 + 4; // 基本长度
	
	/**
	 * 连接超时默认时间<br>
	 * 10秒
	 */
	public static final long CONNECT_TIMEOUT_DEFAULT = 10 * 1000;
	/**
	 * 读取超时默认时间
	 * 10秒
	 */
	public static final long READ_TIMEOUT_DEFAULT = 10 * 1000;

}
